{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "fa593487",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/agent/openai_agent_query_plan.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "034e355d-83a0-4bd2-877e-0f493c5f713d",
   "metadata": {},
   "source": [
    "# OpenAI Agent Query Planning\n",
    "In this demo, we explore adding a `QueryPlanTool` to an `OpenAIAgent`. This effectively enables the agent\n",
    "to do advanced query planning, all through a single tool! \n",
    "\n",
    "The `QueryPlanTool` is designed to work well with the OpenAI Function API. The tool takes in a set of other tools as input.\n",
    "The tool function signature contains of a QueryPlan Pydantic object, which can in turn contain a DAG of QueryNode objects defining a compute graph.\n",
    "The agent is responsible for defining this graph through the function signature when calling the tool. The tool itself executes the DAG over any corresponding tools.\n",
    "\n",
    "In this setting we use a familiar example: Uber 10Q filings in March, June, and September of 2022."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "dc72e6f9",
   "metadata": {},
   "source": [
    "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4df080d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install llama-index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14fdc69e-4c3a-4b4a-babf-3733a0ba2d48",
   "metadata": {},
   "outputs": [],
   "source": [
    "# # uncomment to turn on logging\n",
    "# import logging\n",
    "# import sys\n",
    "\n",
    "# logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
    "# logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c225e522-1ebd-436f-9c47-8738eb513880",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c1e705a-36f2-4272-8f98-7f3785e76e8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index import (\n",
    "    SimpleDirectoryReader,\n",
    "    ServiceContext,\n",
    "    GPTVectorStoreIndex,\n",
    ")\n",
    "from llama_index.response.pprint_utils import pprint_response\n",
    "from llama_index.llms import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35364259-f1c3-4df0-b8c9-79e0afca7436",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = OpenAI(temperature=0, model=\"gpt-4\")\n",
    "service_context = ServiceContext.from_defaults(llm=llm)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "26f545cd",
   "metadata": {},
   "source": [
    "## Download Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6385d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "!mkdir -p 'data/10q/'\n",
    "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/10q/uber_10q_march_2022.pdf' -O 'data/10q/uber_10q_march_2022.pdf'\n",
    "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/10q/uber_10q_june_2022.pdf' -O 'data/10q/uber_10q_june_2022.pdf'\n",
    "!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/10q/uber_10q_sept_2022.pdf' -O 'data/10q/uber_10q_sept_2022.pdf'"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "e7113434-0e41-46b6-a74e-284ce211fd38",
   "metadata": {},
   "source": [
    "## Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d036819a-754e-460b-8734-8af7071287e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "march_2022 = SimpleDirectoryReader(\n",
    "    input_files=[\"./data/10q/uber_10q_march_2022.pdf\"]\n",
    ").load_data()\n",
    "june_2022 = SimpleDirectoryReader(\n",
    "    input_files=[\"./data/10q/uber_10q_june_2022.pdf\"]\n",
    ").load_data()\n",
    "sept_2022 = SimpleDirectoryReader(\n",
    "    input_files=[\"./data/10q/uber_10q_sept_2022.pdf\"]\n",
    ").load_data()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "fd541b68-c67f-4cbf-b579-5437d48e5b8f",
   "metadata": {},
   "source": [
    "## Build indices\n",
    "\n",
    "We build a vector index / query engine over each of the documents (March, June, September)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e6c3178-6aab-4fdc-99f6-c820661e7a73",
   "metadata": {},
   "outputs": [],
   "source": [
    "march_index = GPTVectorStoreIndex.from_documents(march_2022)\n",
    "june_index = GPTVectorStoreIndex.from_documents(june_2022)\n",
    "sept_index = GPTVectorStoreIndex.from_documents(sept_2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3af29f86-9a18-4b8e-af38-8ddc24b550e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "march_engine = march_index.as_query_engine(\n",
    "    similarity_top_k=3, service_context=service_context\n",
    ")\n",
    "june_engine = june_index.as_query_engine(\n",
    "    similarity_top_k=3, service_context=service_context\n",
    ")\n",
    "sept_engine = sept_index.as_query_engine(\n",
    "    similarity_top_k=3, service_context=service_context\n",
    ")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "2d6471ed-5645-4bb0-b8db-1b964ff7cd23",
   "metadata": {},
   "source": [
    "## OpenAI Function Agent with a Query Plan Tool\n",
    "\n",
    "Use OpenAIAgent, built on top of the OpenAI tool use interface.\n",
    "\n",
    "Feed it our QueryPlanTool, which is a Tool that takes in other tools. And the agent to generate a query plan DAG over these tools."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a89972cc-f7b8-4ebd-9c39-935e8a3671ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.tools import QueryEngineTool\n",
    "\n",
    "\n",
    "query_tool_sept = QueryEngineTool.from_defaults(\n",
    "    query_engine=sept_engine,\n",
    "    name=\"sept_2022\",\n",
    "    description=(\n",
    "        f\"Provides information about Uber quarterly financials ending\"\n",
    "        f\" September 2022\"\n",
    "    ),\n",
    ")\n",
    "query_tool_june = QueryEngineTool.from_defaults(\n",
    "    query_engine=june_engine,\n",
    "    name=\"june_2022\",\n",
    "    description=(\n",
    "        f\"Provides information about Uber quarterly financials ending June\"\n",
    "        f\" 2022\"\n",
    "    ),\n",
    ")\n",
    "query_tool_march = QueryEngineTool.from_defaults(\n",
    "    query_engine=march_engine,\n",
    "    name=\"march_2022\",\n",
    "    description=(\n",
    "        f\"Provides information about Uber quarterly financials ending March\"\n",
    "        f\" 2022\"\n",
    "    ),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ae6d0bd-bd85-4f99-8363-96e203156933",
   "metadata": {},
   "outputs": [],
   "source": [
    "# define query plan tool\n",
    "from llama_index.tools import QueryPlanTool\n",
    "from llama_index import get_response_synthesizer\n",
    "\n",
    "response_synthesizer = get_response_synthesizer(\n",
    "    service_context=service_context\n",
    ")\n",
    "query_plan_tool = QueryPlanTool.from_defaults(\n",
    "    query_engine_tools=[query_tool_sept, query_tool_june, query_tool_march],\n",
    "    response_synthesizer=response_synthesizer,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "320e8bde-6afc-4896-94bf-7a186f94fa49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'query_plan_tool',\n",
       " 'description': '        This is a query plan tool that takes in a list of tools and executes a query plan over these tools to answer a query. The query plan is a DAG of query nodes.\\n\\nGiven a list of tool names and the query plan schema, you can choose to generate a query plan to answer a question.\\n\\nThe tool names and descriptions are as follows:\\n\\n\\n\\n        Tool Name: sept_2022\\nTool Description: Provides information about Uber quarterly financials ending September 2022 \\n\\nTool Name: june_2022\\nTool Description: Provides information about Uber quarterly financials ending June 2022 \\n\\nTool Name: march_2022\\nTool Description: Provides information about Uber quarterly financials ending March 2022 \\n        ',\n",
       " 'parameters': {'title': 'QueryPlan',\n",
       "  'description': \"Query plan.\\n\\nContains a list of QueryNode objects (which is a recursive object).\\nOut of the list of QueryNode objects, one of them must be the root node.\\nThe root node is the one that isn't a dependency of any other node.\",\n",
       "  'type': 'object',\n",
       "  'properties': {'nodes': {'title': 'Nodes',\n",
       "    'description': 'The original question we are asking.',\n",
       "    'type': 'array',\n",
       "    'items': {'$ref': '#/definitions/QueryNode'}}},\n",
       "  'required': ['nodes'],\n",
       "  'definitions': {'QueryNode': {'title': 'QueryNode',\n",
       "    'description': 'Query node.\\n\\nA query node represents a query (query_str) that must be answered.\\nIt can either be answered by a tool (tool_name), or by a list of child nodes\\n(child_nodes).\\nThe tool_name and child_nodes fields are mutually exclusive.',\n",
       "    'type': 'object',\n",
       "    'properties': {'id': {'title': 'Id',\n",
       "      'description': 'ID of the query node.',\n",
       "      'type': 'integer'},\n",
       "     'query_str': {'title': 'Query Str',\n",
       "      'description': 'Question we are asking. This is the query string that will be executed. ',\n",
       "      'type': 'string'},\n",
       "     'tool_name': {'title': 'Tool Name',\n",
       "      'description': 'Name of the tool to execute the `query_str`.',\n",
       "      'type': 'string'},\n",
       "     'dependencies': {'title': 'Dependencies',\n",
       "      'description': 'List of sub-questions that need to be answered in order to answer the question given by `query_str`.Should be blank if there are no sub-questions to be specified, in which case `tool_name` is specified.',\n",
       "      'type': 'array',\n",
       "      'items': {'type': 'integer'}}},\n",
       "    'required': ['id', 'query_str']}}}}"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query_plan_tool.metadata.to_openai_tool()  # to_openai_function() deprecated"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6466d4bf-59bd-4916-bf28-c1eb71a0a650",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.agent import OpenAIAgent\n",
    "from llama_index.llms import OpenAI\n",
    "\n",
    "\n",
    "agent = OpenAIAgent.from_tools(\n",
    "    [query_plan_tool],\n",
    "    max_function_calls=10,\n",
    "    llm=OpenAI(temperature=0, model=\"gpt-4-0613\"),\n",
    "    verbose=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51cb85a5-8539-4218-b337-521ba77771a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = agent.query(\"What were the risk factors in sept 2022?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4778a8b-c2de-494c-b825-d0fe3c1d4aac",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.tools.query_plan import QueryPlan, QueryNode\n",
    "\n",
    "query_plan = QueryPlan(\n",
    "    nodes=[\n",
    "        QueryNode(\n",
    "            id=1,\n",
    "            query_str=\"risk factors\",\n",
    "            tool_name=\"sept_2022\",\n",
    "            dependencies=[],\n",
    "        )\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f056a81-cf16-4c05-aa3b-4439f2dc808d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'title': 'QueryPlan',\n",
       " 'description': 'Query plan.\\n\\nContains the root QueryNode (which is a recursive object).\\nThe root node should contain the original query string to be executed.\\n\\nExample query plan in JSON format:\\n\\n```json\\n{\\n    \"root\": {\\n        \"query_str\": \"Compare the demographics of France and Italy.\",\\n        \"child_nodes\": [\\n            {\\n                \"query_str\": \"What are the demographics of France?\",\\n                \"tool_name\": \"france_demographics\",\\n                \"child_nodes\": []\\n            },\\n            {\\n                \"query_str\": \"What are the demographics of Italy?\",\\n                \"tool_name\": \"italy_demographics\",\\n                \"child_nodes\": []\\n            }\\n        ]\\n    }\\n}\\n```',\n",
       " 'type': 'object',\n",
       " 'properties': {'root': {'title': 'Root',\n",
       "   'description': 'Root node of the query plan. Should contain the original query string to be executed.',\n",
       "   'allOf': [{'$ref': '#/definitions/QueryNode'}]}},\n",
       " 'required': ['root'],\n",
       " 'definitions': {'QueryNode': {'title': 'QueryNode',\n",
       "   'description': 'Query node.\\n\\nA query node represents a query (query_str) that must be answered.\\nIt can either be answered by a tool (tool_name), or by a list of child nodes\\n(child_nodes).\\nThe tool_name and child_nodes fields are mutually exclusive.',\n",
       "   'type': 'object',\n",
       "   'properties': {'query_str': {'title': 'Query Str',\n",
       "     'description': 'Question we are asking. This is the query string that will be executed. We will either provide a tool to execute the query, or a list of child nodes containing sub-questions that will be executed first, and the results of which will be used as context to execute the current query string.',\n",
       "     'type': 'string'},\n",
       "    'tool_name': {'title': 'Tool Name',\n",
       "     'description': 'Name of the tool to execute the `query_str`.',\n",
       "     'type': 'string'},\n",
       "    'child_nodes': {'title': 'Child Nodes',\n",
       "     'description': 'List of child nodes representing sub-questions that need to be answered in order to answer the question given by `query_str`.Should be blank if `tool_name` is specified.',\n",
       "     'type': 'array',\n",
       "     'items': {'$ref': '#/definitions/QueryNode'}}},\n",
       "   'required': ['query_str', 'child_nodes']}}}"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QueryPlan.schema()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "feeb0afc-96c8-4be5-839c-ce8a64fb9e71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=== Calling Function ===\n",
      "Calling function: query_plan_tool with args: {\n",
      "  \"nodes\": [\n",
      "    {\n",
      "      \"id\": 1,\n",
      "      \"query_str\": \"What is Uber's revenue for March 2022?\",\n",
      "      \"tool_name\": \"march_2022\",\n",
      "      \"dependencies\": []\n",
      "    },\n",
      "    {\n",
      "      \"id\": 2,\n",
      "      \"query_str\": \"What is Uber's revenue for June 2022?\",\n",
      "      \"tool_name\": \"june_2022\",\n",
      "      \"dependencies\": []\n",
      "    },\n",
      "    {\n",
      "      \"id\": 3,\n",
      "      \"query_str\": \"What is Uber's revenue for September 2022?\",\n",
      "      \"tool_name\": \"sept_2022\",\n",
      "      \"dependencies\": []\n",
      "    },\n",
      "    {\n",
      "      \"id\": 4,\n",
      "      \"query_str\": \"Analyze Uber revenue growth in March, June, and September\",\n",
      "      \"tool_name\": \"revenue_growth_analyzer\",\n",
      "      \"dependencies\": [1, 2, 3]\n",
      "    }\n",
      "  ]\n",
      "}\n",
      "\u001b[36;1m\u001b[1;3mExecuting node {\"id\": 4, \"query_str\": \"Analyze Uber revenue growth in March, June, and September\", \"tool_name\": \"revenue_growth_analyzer\", \"dependencies\": [1, 2, 3]}\n",
      "\u001b[0m\u001b[38;5;200m\u001b[1;3mExecuting 3 child nodes\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuting node {\"id\": 1, \"query_str\": \"What is Uber's revenue for March 2022?\", \"tool_name\": \"march_2022\", \"dependencies\": []}\n",
      "\u001b[0m\u001b[38;5;200m\u001b[1;3mSelected Tool: ToolMetadata(description='Provides information about Uber quarterly financials ending March 2022', name='march_2022', fn_schema=None)\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuted query, got response.\n",
      "Query: What is Uber's revenue for March 2022?\n",
      "Response: Uber's revenue for March 2022 was $6.854 billion.\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuting node {\"id\": 2, \"query_str\": \"What is Uber's revenue for June 2022?\", \"tool_name\": \"june_2022\", \"dependencies\": []}\n",
      "\u001b[0m\u001b[38;5;200m\u001b[1;3mSelected Tool: ToolMetadata(description='Provides information about Uber quarterly financials ending June 2022', name='june_2022', fn_schema=None)\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuted query, got response.\n",
      "Query: What is Uber's revenue for June 2022?\n",
      "Response: Uber's revenue for June 2022 cannot be determined from the provided information. However, the revenue for the three months ended June 30, 2022, was $8,073 million.\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuting node {\"id\": 3, \"query_str\": \"What is Uber's revenue for September 2022?\", \"tool_name\": \"sept_2022\", \"dependencies\": []}\n",
      "\u001b[0m\u001b[38;5;200m\u001b[1;3mSelected Tool: ToolMetadata(description='Provides information about Uber quarterly financials ending September 2022', name='sept_2022', fn_schema=None)\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mExecuted query, got response.\n",
      "Query: What is Uber's revenue for September 2022?\n",
      "Response: Uber's revenue for the three months ended September 30, 2022, was $8.343 billion.\n",
      "\u001b[0mGot output: Based on the provided context information, we can analyze Uber's revenue growth as follows:\n",
      "\n",
      "- In March 2022, Uber's revenue was $6.854 billion.\n",
      "- For the three months ended June 30, 2022, Uber's revenue was $8,073 million (or $8.073 billion). However, we do not have the specific revenue for June 2022.\n",
      "- For the three months ended September 30, 2022, Uber's revenue was $8.343 billion.\n",
      "\n",
      "From this information, we can observe that Uber's revenue has been growing between the periods mentioned. The revenue increased from $6.854 billion in March 2022 to $8.073 billion for the three months ended June 2022, and further increased to $8.343 billion for the three months ended September 2022. However, we cannot provide a month-by-month analysis for June and September as the specific monthly revenue figures are not available.\n",
      "========================\n"
     ]
    }
   ],
   "source": [
    "response = agent.query(\n",
    "    \"Analyze Uber revenue growth in March, June, and September\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53bfd23d-cbb8-40ce-8bb7-feb3001398dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Based on the provided context information, we can analyze Uber's revenue growth for the three-month periods ending in March, June, and September.\n",
      "\n",
      "1. For the three months ended March 31, 2022, Uber's revenue was $6.854 billion.\n",
      "2. For the three months ended June 30, 2022, Uber's revenue was $8.073 billion.\n",
      "3. For the three months ended September 30, 2022, Uber's revenue was $8.343 billion.\n",
      "\n",
      "To analyze the growth, we can compare the revenue figures for each period:\n",
      "\n",
      "- From March to June, Uber's revenue increased by $1.219 billion ($8.073 billion - $6.854 billion), which represents a growth of approximately 17.8% (($1.219 billion / $6.854 billion) * 100).\n",
      "- From June to September, Uber's revenue increased by $0.270 billion ($8.343 billion - $8.073 billion), which represents a growth of approximately 3.3% (($0.270 billion / $8.073 billion) * 100).\n",
      "\n",
      "In summary, Uber experienced significant revenue growth of 17.8% between the three-month periods ending in March and June, followed by a smaller growth of 3.3% between the periods ending in June and September.\n"
     ]
    }
   ],
   "source": [
    "print(str(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5bae0b65-59f5-4b5b-b5a7-1d8c5c4aa308",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = agent.query(\n",
    "    \"Analyze changes in risk factors in march, june, and september for Uber\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01703941-f016-47d3-9cf9-fefac0fb54e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(str(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebd52c07-0e46-4edd-8201-caa72b25ae1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# response = agent.query(\"Analyze both Uber revenue growth and risk factors over march, june, and september\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c47e41be-d61c-4992-b1c7-e038e1860d33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Based on the provided context information, we can analyze Uber's revenue growth for the three-month periods ending in March, June, and September.\n",
      "\n",
      "1. For the three months ended March 31, 2022, Uber's revenue was $6.854 billion.\n",
      "2. For the three months ended June 30, 2022, Uber's revenue was $8.073 billion.\n",
      "3. For the three months ended September 30, 2022, Uber's revenue was $8.343 billion.\n",
      "\n",
      "To analyze the growth, we can compare the revenue figures for each period:\n",
      "\n",
      "- From March to June, Uber's revenue increased by $1.219 billion ($8.073 billion - $6.854 billion), which represents a growth of approximately 17.8% (($1.219 billion / $6.854 billion) * 100).\n",
      "- From June to September, Uber's revenue increased by $0.270 billion ($8.343 billion - $8.073 billion), which represents a growth of approximately 3.3% (($0.270 billion / $8.073 billion) * 100).\n",
      "\n",
      "In summary, Uber experienced significant revenue growth of 17.8% between the three-month periods ending in March and June, followed by a smaller growth of 3.3% between the periods ending in June and September.\n"
     ]
    }
   ],
   "source": [
    "print(str(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba9d02e4-4c5c-47d2-8cf4-62bcc967e6f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = agent.query(\n",
    "    \"First look at Uber's revenue growth and risk factors in March, \"\n",
    "    + \"then revenue growth and risk factors in September, and then compare and\"\n",
    "    \" contrast the two documents?\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "598f6f3c-e5ac-401b-925a-7a6cce0620bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "response"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llama_index_v2",
   "language": "python",
   "name": "llama_index_v2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
